# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     day170_pyqt5_drawText
   Description :
   Author :       fuml
   date：          2019/9/23
-------------------------------------------------
   Change Activity:
                   2019/9/23:In this example, we draw text in Russian azbuka.
-------------------------------------------------
"""
import sys,random
from PyQt5.QtWidgets import QWidget,QApplication
from PyQt5.QtGui import QPainter,QColor,QFont
from PyQt5.QtCore import Qt

class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.text="hello world"

        self.setGeometry(300,300,280,170)
        self.setWindowTitle('Draw text')
        self.show()

    def paintEvent(self, event):
        qp = QPainter()
        qp.begin(self)
        self.drawText(event,qp)
        self.draw1000(qp)
        qp.end()

    def drawText(self,event,qp):
        qp.setPen(QColor(168,34,3))
        qp.setFont(QFont('Decorative',10))
        qp.drawText(event.rect(),Qt.AlignCenter,self.text)

    def draw1000(self, qp):
        qp.setPen(Qt.red)
        size = self.size()

        for i in range(1000):
            x = random.randint(1, size.width() - 1)
            y = random.randint(1, size.height() - 1)
            qp.drawPoint(x, y)

if __name__ == '__main__':
    app =QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())